import 'package:super_timetable_front/utils/date_utils.dart';

import 'paging_model.dart';
import 'result_model.dart';

///学校教师:查询:请求
class SchoolTeacherQueryReq extends PagingQueryReq {
  final String schoolId, name;
  final int status;

  SchoolTeacherQueryReq({
    required this.schoolId,
    required this.name,
    required this.status,
    super.index,
    super.size,
  });

  @override
  Map<String, dynamic> toMap() {
    final map = super.toMap();
    map['name'] = name;
    map['status'] = status;
    return map;
  }
}

///学校教师:查询:响应
class SchoolTeacherQueryRes extends PagingQueryRes<SchoolTeacherItemRes> {
  SchoolTeacherQueryRes({
    required super.retCode,
    required super.retMessage,
    super.total,
    super.rows,
  });

  factory SchoolTeacherQueryRes.fromModel(final ResultModelRes res) {
    final ret = PagingQueryRes.fromModel(
      res,
      (row) => SchoolTeacherItemRes.fromMap(row),
    );
    return SchoolTeacherQueryRes(
      retCode: ret.retCode,
      retMessage: ret.retMessage,
      total: ret.total,
      rows: ret.rows,
    );
  }
}

///学校教师:数据项:响应
class SchoolTeacherItemRes {
  final String id, code, name, remark;
  final int status;
  final DateTime? createdAt;

  const SchoolTeacherItemRes({
    required this.id,
    required this.code,
    required this.name,
    required this.remark,
    required this.status,
    required this.createdAt,
  });

  factory SchoolTeacherItemRes.fromMap(final Map<String, dynamic> map) =>
      SchoolTeacherItemRes(
        id: map['id'] ?? '',
        code: map['code'] ?? '',
        name: map['name'] ?? '',
        remark: map['remark'] ?? '',
        status: map['status'] ?? 0,
        createdAt: dateUtils.parse('yyyy-MM-dd HH:mm:ss', map['createdAt']),
      );
}

///学校教师:加载:响应
class SchoolTeacherInfoRes extends SchoolTeacherItemRes with ModelRes {
  @override
  final int retCode;
  @override
  final String retMessage;

  SchoolTeacherInfoRes({
    required this.retCode,
    required this.retMessage,
    required SchoolTeacherItemRes item,
  }) : super(
          id: item.id,
          code: item.code,
          name: item.name,
          remark: item.remark,
          status: item.status,
          createdAt: item.createdAt,
        );

  factory SchoolTeacherInfoRes.fromModel(final ResultModelRes res) =>
      SchoolTeacherInfoRes(
        retCode: res.retCode,
        retMessage: res.retMessage,
        item: SchoolTeacherItemRes.fromMap(res.toMap),
      );
}

///学校教师:新增:请求
class SchoolTeacherAddReq {
  final String schoolId, code, name, remark;

  const SchoolTeacherAddReq({
    required this.schoolId,
    required this.code,
    required this.name,
    required this.remark,
  });

  Map<String, dynamic> toMap() => {
        'code': code,
        'name': name,
        'remark': remark,
      };
}

///学校教师:修改:请求
class SchoolTeacherModifyReq {
  final String id, code, name, remark;
  final int status;

  const SchoolTeacherModifyReq({
    required this.id,
    required this.code,
    required this.name,
    required this.remark,
    required this.status,
  });

  Map<String, dynamic> toMap() => {
        'code': code,
        'name': name,
        'remark': remark,
        'status': status,
      };
}
